package com.venus.mq.netty.client;

/**
 * Created by mc on 18/5/29.
 */
import com.venus.mq.model.MqResponse;
import com.venus.mq.serialization.SerializeType;
import com.venus.mq.model.Topic;
import com.venus.mq.netty.NettyDecoderHandler;
import com.venus.mq.netty.NettyEncoderHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;

/**
 *
 * Title: NettyClientFilter
 */
public class NettyClientFilter extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline ph = ch.pipeline();
        /*
         * 解码和编码，应和服务端一致
         **/
        ph.addLast("encoder", new NettyEncoderHandler(SerializeType.JACKSON));
        ph.addLast("decoder", new NettyDecoderHandler(MqResponse.class,SerializeType.JACKSON));
        ph.addLast("handler", new NettyClientHandler()); //客户端的逻辑
    }
}